﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using Storage;
using Storage.EntityModels;
using System.Data.Linq;

namespace Stats
{
    class DataBasePopulator
    {
        public static void populateDailyTable()
        {
            int number = 400;
            TripLoaDataContext db = Storage.StorageManager.Instance.Entities;
            DateTime dt = DateTime.Today;
            Random rand = new Random(DateTime.Now.Millisecond);
            int oldRegisteredUSersCount = 0;
            dt = dt.AddDays(-400);

            for (int i = 0; i < number; i++)
            {
                DailyStatistics updateDaily = new DailyStatistics();
                updateDaily.Date = dt;
                updateDaily.FuelSaved = (float)rand.Next(30, 200);
                updateDaily.MoneySaved = (decimal)(updateDaily.FuelSaved * 140) / 10; ;
                updateDaily.PollutionSaved = (float)rand.Next(5, 60) / 10;
                updateDaily.TotalDailyTripProposal = rand.Next(15, 40);
                updateDaily.TotalKilometers = (float)rand.Next(10, 500);
                updateDaily.TotalPassengers = rand.Next(20, 60);
                updateDaily.RegisteredUsersCount = rand.Next(1, 7);
                updateDaily.MaximumPassengers = rand.Next(3, 9);
                updateDaily.DailyCompletedTrips = rand.Next(15, 40);
                updateDaily.PassengerCarriedAlongTheWay = rand.Next(10, 50);
                updateDaily.AverageTripKm = rand.Next(30, 400);
                updateDaily.MissedAppointmentsByDrivers = rand.Next(5, 15);
                updateDaily.MissedAppointmentsByPassengers = rand.Next(5, 15);
                updateDaily.RegisteredUsersCount = rand.Next(5, 15) + oldRegisteredUSersCount;

                oldRegisteredUSersCount = updateDaily.RegisteredUsersCount;

                dt = dt.AddDays(1);

                StorageManager.Instance.Entities.DailyStatistics.InsertOnSubmit(updateDaily);
                StorageManager.Instance.Entities.SubmitChanges();
            }
        }
    }
}
